package com.baitiaojun.video.api;

import com.baitiaojun.api.exception.ConditionException;
import com.baitiaojun.api.vo.JsonRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @类名 FileApi
 * @描述 前端：生成分片——>发起请求：获取md5——>分片上传文件——>获取（帧截取url、视频url、时长）——>生成弹幕遮罩——>添加视频信息
 * @作者 白条君
 * @创建日期 2022/12/14 17:08
 * @版本 1.0
 */
@Api("视频文件接口")
@RequestMapping("/video/file")
public interface FileApi {

    @ApiOperation("获取文件md5")
    @PostMapping("/file-md5")
    JsonRes getFileMd5(@ApiParam(value = "文件", required = true) @RequestBody MultipartFile file);

    @ApiOperation(value = "获取分片", hidden = true)
    @PostMapping("/file-slice")
    JsonRes getFileSlice(@ApiParam(value = "文件", required = true) @RequestBody MultipartFile file,
            @ApiParam(value= "md5", required = true) @RequestParam String md5) throws IOException, ConditionException;

    @ApiOperation("文件断点续传")
    @PutMapping("/fast-upload-file")
    JsonRes fastUploadFile(@ApiParam(value = "文件", required = true) @RequestBody MultipartFile file
            ,@ApiParam(value = "md5", required = true) @RequestParam String md5
            ,@ApiParam(value = "分片下标", required = true) @RequestParam String sliceNo
            ,@ApiParam(value = "分片总大小", required = true) @RequestParam String totalSize) throws Exception;

    @ApiOperation(value = "分片获取视频文件", notes = "请求头需要添加获取分片的范围")
    @GetMapping("/partial-content")
    void getPartialContent(HttpServletResponse response
            , @ApiParam(value = "文件路径", required = true) @RequestParam String filePath) throws Exception;

    @ApiOperation("获取视频缩略图")
    @GetMapping("/video-thumbnail")
    void getVideoThumbnail(@ApiParam(value = "文件路径", required = true) @RequestParam String filePath) throws Exception;

    @ApiOperation("上传自定义视频封面")
    @PostMapping("/upload-thumbnail")
    JsonRes uploadThumbnail(@ApiParam(value = "文件", required = true) @RequestBody MultipartFile file) throws Exception;

    /**
     * 生成弹幕遮罩
     */
    @ApiOperation("生成弹幕遮罩")
    @PostMapping("/generic-bullet-screen-mask")
    JsonRes genericBulletScreenMask(@ApiParam(value = "视频id", required = true) @RequestParam Long videoId
            , @ApiParam(value = "视频文件的md5", required = true) @RequestParam String md5) throws Exception;

    /**
     * 获取弹幕遮罩
     */
    @ApiOperation("获取弹幕遮罩")
    @GetMapping("/bullet-screen-mask")
    JsonRes getBulletScreenMask(@ApiParam(value = "视频id", required = true) @RequestParam Long videoId
            , @ApiParam(value = "视频url", required = true) @RequestParam String url, HttpServletResponse response) throws Exception;
}